package com.dongnao.demo.database.db;

import android.database.sqlite.SQLiteDatabase;
import android.os.Environment;
import android.util.Log;

import com.dongnao.demo.database.Config;

public class BaseDaoFactory {
    private static final String TAG = "BaseDaoFactory";

    private static final BaseDaoFactory sInstance = new BaseDaoFactory();

    public static BaseDaoFactory getInstance(){
        return sInstance;
    }

    private SQLiteDatabase sqLiteDatabase;

    private BaseDaoFactory(){
        try {
//            sqLiteDatabase = SQLiteDatabase.openOrCreateDatabase(Config.DB_PATH, null);
            sqLiteDatabase = SQLiteDatabase.create(null);
        }catch (Exception e){
            Log.e(TAG, "BaseDaoFactory: ", e);
        }
    }

    public <T> BaseDao<T> getBaseDao(Class<T> entityClass){
        BaseDao<T> dao = null;
        try{
            dao = BaseDao.class.newInstance();
            dao.init(sqLiteDatabase, entityClass);
        }catch (Exception e){
            Log.e(TAG, "getBaseDao: ", e);
        }
        return dao;
    }
}
